<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="com.tjtt.tdm.base.PubMethod" %>
<%@ page language="java" import="com.tjtt.common.utils.DateUtilsAll"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  
  <head>
  <base target="_self"/>
  
  <title>选择审核人员</title>
  	<%@ include file="../jslib/jquerylib.jsp" %> 
	<link rel="stylesheet" type="text/css" href="<%=path %>/web/style/layout.css" />
    <script type="text/javascript" src="<%=path %>/jslib/jquery.validate.min.js"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js"  defer="defer"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/jquery.form.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/additional-methods.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/icon.css" />
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/demo.css" />
	<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>

    <c:if test="${requestScope.message!=null}">
		<script type="text/javascript">
 	 		     alert('<c:out value="${requestScope.message}"></c:out>');
 	 		     window.close();
 		</script>
	</c:if> 
    <script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    var stateValue="";
    var flowtaskid = '${flowtaskId}';
    $().ready(function(){
    	
		//样品列表
		  $("#gridTableSample").jqGrid({
			url:common_basePath+'autoForms/item!queryZCSampleByTaskId.action?taskId='+flowtaskid,
			datatype: "json",
			height: 150,
			width: 720, 
			colNames:['主键','样品名称','车辆名称','样品数量','批次号/规格型号','VIN号','应用车型','整车型号','车辆型号','生产商','设计乘员','整备质量','约定送样日期','样品处理','最高车','行驶里程','动力类型','附件'],
			colModel:[
				{name:'ID',index:'ID', width:70,key:true,hidden:true}, 
				{name:'T_SAMPLENAME',index:'T_SAMPLENAME', width:100}, 
				{name:'CHELIANGNAME',index:'CHELIANGNAME', width:100,hidden:true}, 
				{name:'T_SAMPLECOUNT',index:'T_SAMPLECOUNT', width:40}, 
				{name:'T_PICI',index:'T_PICI', width:70}, 
				{name:'VIN',index:'VIN', width:70},
				{name:'T_YINGYONGCHEXING',index:'T_YINGYONGCHEXING', width:80}, 
				{name:'T_CHEXINGBIANMA',index:'T_CHEXINGBIANMA', width:70}, 
				{name:'CHELIANGXINGHAO',index:'CHELIANGXINGHAO', width:70,hidden:true}, 
				{name:'T_MANUFACTURER',index:'T_MANUFACTURER', width:70},
				{name:'CHENGYUAN',index:'CHENGYUAN', width:70},
				{name:'ZHENGBEIZHILIANG',index:'ZHENGBEIZHILIANG', width:70},
				{name:'T_SONGYANGDATE',index:'T_SONGYANGDATE', width:70},
				{name:'T_SAMPLECHULI',index:'T_SAMPLECHULI', width:70},
				{name:'ZUIGAOCHE',index:'ZUIGAOCHE', width:70},
				{name:'LICHENG',index:'LICHENG', width:70},
				{name:'DONGLILEIXING',index:'DONGLILEIXING', width:70},
				{name:'FILE_NAME',index:'FILE_NAME', width:180,hidden:true,hidedlg:false,formatter: function(cellvalue, options, rowObject) {        return "<a href='javascript:downloafAnnex(0,"+rowObject.T_ANNEX+")'>"+rowObject.FILE_NAME+"</a>" }}
			],   
			shrinkToFit:false,
			sortname:'ID',
			sortorder:'asc',
			viewrecords:true,
			multiselect: true, // 是否显示复选框
			multiboxonly : true, 
			rownumbers: false,//显示行号
		    cellEdit: false,
			forceFit : true, 
			rowNum:200,
			mtype: "POST", 
			rowList:[15,20,50,200,500],
			toolbar: [false,"top"],
			jsonReader: {
				root:"rows",		// 数据行（默认为：rows）
				page: "page",  	// 当前页
				total: "total",  // 总页数
				records: "records",  // 总记录数
				repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
			},
			prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
			pager:"#gridPagerSample",
			caption: "样品列表"
		});	 
		//检测项目
		var lastsel3;
		var biaozhunweituo = "";
		$("#gridTableItem1").jqGrid({
		url:common_basePath+'autoForms/item!queryItemByTaskId.action?type=0&taskId='+flowtaskid,
		datatype: "json",
		height: 150,
		width: 720, 
		colNames:['ID','检测项目','标准数量','标准委托','报告形式','报告要求','附件名称','检测费用','检测标准'],
		colModel:[
			{name:'ID',index:'ID', width:70,key:true,hidden:true}, 
			{name:'T_ITEMNAME',index:'T_ITEMNAME', width:180}, 
			{name:'bzcount',index:'bzcount', width:70,hidden:true}, 
			{name:'T_BIAOZHUNWEITUO',index:'T_BIAOZHUNWEITUO', width:80,editable: true,edittype:'select',editoptions:{value:'否:否;是:是'},formatter: function (cellvalue, options, rowObject) {
				if(rowObject.bzcount>0){ 
					biaozhunweituo='否';
					}else{ 
						biaozhunweituo='是';
					}
					return biaozhunweituo;
		       }},
			{name:'T_BAOGAOTYPE',index:'T_BAOGAOTYPE', width:100,editable:true,edittype:'select',editoptions:{value:'出具检测报告:出具检测报告;出具原始记录:出具原始记录',dataEvents:[        {type: 'change',fn: function(e) { 
				    var bgtype = $(this).val(); 
				    var rowid = $(this).parent().parent().attr('ID');
	         	if(bgtype=='出具原始记录'){ 
	                jQuery("#gridTableItem1").jqGrid('setRowData',rowid,{T_BGYAOQIU:''}); 	        }          	else if(bgtype=='出具检测报告'){
	                var msg = '<select class="editable" id="'+rowid+'_T_BGYAOQIU" submitName="T_BGYAOQIU" role="select" size="1"><option role="option" value="中文">中文</option><option role="option" value="英文">英文</option><option role="option" value="中英文">中英文</option></select>';                $("#gridTableItem1").jqGrid('setCell',rowid,'T_BGYAOQIU',msg);  	        }         }}]}}, 
			{name:'T_BGYAOQIU',index:'T_BGYAOQIU', width:80,editable: true,edittype:'select',editoptions:{value:'中文:中文;英文:英文;中英文:中英文'}}, 
	     {name:'FILE_NAME',index:'FILE_NAME', width:180,hidden:true,hidedlg:false,formatter: function(cellvalue, options, rowObject) {        return "<a href='javascript:downloafAnnex(0,"+rowObject.T_ANNEX+")'>"+rowObject.FILE_NAME+"</a>" }},		{name:'T_JIANCEMONEY',index:'T_JIANCEMONEY', width:80}, 
			{name:'T_JIANCEBIAOZHUN',index:'T_JIANCEBIAOZHUN', width:200} 
		],  
	onSelectRow: function(id){ 
//	   if(id && id!==lastsel3){
	      jQuery('#gridTableItem1').jqGrid('editRow',id,true);
	      lastsel3=id;
//	   }
	}, 
		shrinkToFit:false,
		sortname:'T_ITEMID',
		sortorder:'asc',
		viewrecords:true,
		multiselect: true, // 是否显示复选框
		multiboxonly : true, 
		rownumbers: false,//显示行号
	 cellEdit: false,
		forceFit : true, 
		rowNum:200,
		mtype: "POST", 
		rowList:[15,20,50,200,500],
		toolbar: [false,"top"],
		jsonReader: {
			root:"rows",		// 数据行（默认为：rows）
			page: "page",  	// 当前页
			total: "total",  // 总页数
			records: "records",  // 总记录数
			repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
		},
		prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
		pager:"#gridPagerItem1",
		caption: "检测项目列表"
	});
	//其他检测项目
	var lastsel3;
	$("#gridTableItem2").jqGrid({
			url:common_basePath+'autoForms/item!queryItemByTaskId.action?type=1&taskId='+flowtaskid,
			datatype: "json",
			height: 150,
			width: 720, 
			colNames:['主键','检测项目','标准委托','报告形式','报告要求','附件名称','项目ID'],
			colModel:[
				{name:'ID',index:'ID', width:70,key:true}, 
				{name:'T_ITEMNAME',index:'T_ITEMNAME', width:180}, 
				{name:'T_BIAOZHUNWEITUO',index:'T_BIAOZHUNWEITUO', width:80,editable: true,edittype:'select',editoptions:{value:'否:否;是:是'}},
				{name:'T_BAOGAOTYPE',index:'T_BAOGAOTYPE', width:180,editable: true,edittype:'select',editoptions:{value:'出具检测报告:出具检测报告;出具原始记录:出具原始记录',dataEvents:[        {type: 'change',fn: function(e) { 
					    var bgtype = $(this).val();
		             var rowid = $(this).parent().parent().attr('ID');             $("gridTableItem2").jqGrid('setSelection',rowid);         	if(bgtype=='出具原始记录'){ 
		                jQuery("#gridTableItem2").jqGrid('setRowData',rowid,{T_BGYAOQIU:''}); 	        }          	else if(bgtype=='出具检测报告'){
		                var msg = '<select class="editable" id="'+lastsel3+'_T_BGYAOQIU" submitName="T_BGYAOQIU" role="select" size="1"><option role="option" value="中文">中文</option><option role="option" value="英文">英文</option><option role="option" value="中英文">中英文</option></select>';                $("#gridTableItem2").jqGrid('setCell',rowid,'T_BGYAOQIU',msg);  	        }         }}]}}, 
				{name:'T_BGYAOQIU',index:'T_BGYAOQIU', width:80,editable: true,edittype:'select',editoptions:{value:'中文:中文;英文:英文;中英文:中英文'}}, 
		     {name:'FILE_NAME',index:'FILE_NAME', width:180,hidden:true,hidedlg:false,formatter: function(cellvalue, options, rowObject) {        return "<a href='javascript:downloafAnnex(0,"+rowObject.T_ANNEX+")'>"+rowObject.FILE_NAME+"</a>"}},		{name:'ITEMFLOWID',index:'ITEMFLOWID', width:180,hidden:true} 
			],   
		onSelectRow: function(id){ 
	//	   if(id && id!==lastsel3){
		      jQuery('#gridTableItem2').jqGrid('editRow',id,true);
		      lastsel3=id;
	//	   }
		}, 
			shrinkToFit:false,
			sortname:'ID',
			sortorder:'asc',
			viewrecords:true,
			multiselect: true, // 是否显示复选框
			multiboxonly : true, 
			rownumbers: false,//显示行号
		 cellEdit: false,
			forceFit : true, 
			rowNum:200,
			mtype: "POST", 
			rowList:[15,20,50,200,500],
			toolbar: [false,"top"],
			jsonReader: {
				root:"rows",		// 数据行（默认为：rows）
				page: "page",  	// 当前页
				total: "total",  // 总页数
				records: "records",  // 总记录数
				repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
			},
			prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
			pager:"#gridPagerItem2",
			caption: "其他检测项目列表"
		});
	
			   
		//保存
		var options = {
	  	    url:"<%=request.getContextPath() %>/weituodan!saveWeituodan.action",
	  	     beforeSubmit: function() {
	   				return checking();
	    			},
	  	    dataType:'json',
	  	    success: function(data) {
	  	      if(data.result=='success'){
				alert("添加成功");
			//	window.close();
				api.close();
				W.refreshIt();
	  	      }
	  	    }};  
	  	var options2 = {
	  	    url:"<%=request.getContextPath() %>/weituodan!updateWeituodan.action",
	  	     beforeSubmit: function() {
	   				return checking();
	    			},
	  	    dataType:'json',
	  	    success: function(data) {
	  	    //alert(data);
	  	      if(data.result=='success'){
				alert("保存成功");
			//	window.close();
				api.close();
				W.refreshIt();
	  	      }
	  	    }};
        //提交  
		var options1 = {
	  	    url:'<%=request.getContextPath() %>/weituodan!submitWeituodan.action',
	  	     beforeSubmit: function() {
	   				return true;
	    			},
	  	    dataType:'json',
	  	    success: function(data) {
	  	    //alert(data);
	  	      if(data.result=='success'){
				alert("提交成功");
			//	window.close();
				api.close();
				W.refreshIt();
	  	      }
	  	    }};
	  	//保存
	  	$('#saveBtn').click(function(){
		  	      //自动保存检测项目
			    saveItemGrid(1);
			    var flag = saveGridOtherItem(1);
			    if(!flag){
			       return false;
			    }
	  	  	  $('#pageFrom').ajaxSubmit(options);
    	 });
    	//提交
		$('#submitBtn').click(function(){
		    if(!checking()){
		    	return false;
		    }
		    //判断样品和检测项目是否为空
		    var sampleIds = $("#gridTableSample").jqGrid('getDataIDs')+"";
		    if(!sampleIds){
		       alert("请添加样品!");
		       return false;
		    }
		    
		    var itemIds1 = $("#gridTableItem1").jqGrid('getDataIDs')+"";
		    var itemIds2 = $("#gridTableItem2").jqGrid('getDataIDs')+"";
		    if(itemIds1==''&&itemIds2==''){
		       alert("请添加检测项目!");
		       return false;
		    }
		    
		    var datas = window.showModalDialog("<%=request.getContextPath() %>/view/zhengchekekaoxingshiyan_choosenextuser.jsp?shenheren=&pizhunren=&ddyname=&ddy=",'',"dialogWidth=400px;dialogHeight=300px");
		    var json2 = eval('('+datas+')');
	    	if("close" == json2.state){
	    	    alert("请选择批准人和接收方代表！");
	    		return false;
	    	}else{
				$("#bianzhirenyuan").val(json2.bianzhirenyuan);
				$("#pizhunrenyuan").val(json2.pizhunrenyuan);
				$("#jieshoufangdaibiao").val(json2.jieshoufangdaibiao);
	    	}
	    	if(!confirm("是否确认提交 ？")){
		   			return false;
				}
			//自动保存检测项目
		    saveItemGrid(1);
		    var flag = saveGridOtherItem(1);
		    if(!flag){
		       return false;
		    }
	    	$('#pageFrom').ajaxSubmit(options1);
	            return false;
    	 });
    	$('#closeBtn').click(function(){
 //   	    deleteFlowTask();
    		api.close();
			//window.close();
		});
		
		
	});
	//点击关闭
	function guanbi(){
         if( null != flowtaskid && "" != flowtaskid){
  //       	deleteFlowTask();
         }
	}
	
	//删除垃圾数据
	function deleteFlowTask(){
		var actionUrl = "<%=request.getContextPath() %>/weituodan!deleteFlowTask.action?flowTaskid="+flowtaskid; 
		var params = {  
			    };   
		$.ajax({  
			  url : actionUrl,  
		      type : "post", 
		      data : params,  
		      dataType : "json",  
		      cache : false,  
		      error : function(textStatus, errorThrown) {  
		          alert("系统ajax交互错误: " + textStatus.value);  
		      },  
		      success : function(data, textStatus) {
		      	if(data.result=='success'){
		      	}else{
		      	}
		    }  
		});
	}
	
   	function checking(){
   		var flag = true;
		var renwuname = $.trim($("#renwuname").val());
		var jiancedanwei = $("#jiancedanwei").val();
		var jiancedidian = $("#jiancedidian").val();
		var shenqingdanwei = $("#shenqingdanwei").val();
		var dizhi = $("#dizhi").val();
		var jiancemudi = $("#jiancemudi").val();
		if(renwuname ==null || renwuname == "" ){
			alert("任务名称不能为空！");
			$("#renwuname").focus();
    		return false;
		}
		if(jiancedanwei ==null || jiancedanwei == "" ){
			alert("检测单位不能为空！");
			$("#jiancedanwei").focus();
    		return false;
		}
		if(jiancedidian ==null || jiancedidian == "" ){
			alert("检测地点不能为空！");
			$("#jiancedidian").focus();
    		return false;
		}
		if(shenqingdanwei ==null || shenqingdanwei == "" ){
			alert("申请单位不能为空！");
			$("#shenqingdanwei").focus();
    		return false;
		}
		if(dizhi ==null || dizhi == "" ){
			alert("地址不能为空！");
			$("#dizhi").focus();
    		return false;
		}
		if(jiancemudi ==null || jiancemudi == "" ){
			alert("检测目的不能为空！");
			$("#jiancemudi").focus();
    		return false;
		}
		return true;
	}
	 
	function checkExp(inputData){ 
		var regEx = new RegExp(/^(([^\^\.<>%&',:;=?$"'#@!~\]\[{}【】￥（）！·‘’”“。，、？：；—|\/\\/`\|])*)$/);
		var result = inputData.match(regEx);
		if (result == null) {
			return false;
		}
		return true;
	}
	function checkNum(inputData){
		var sNumber;
	    sNumber=Number(inputData);
	    if (isNaN(inputData)){
	       return false;
	     }
	    return true;
	}
	function countlen1(textarea){
	       var elem = event.relatedTarget || event.srcElement || event.target ||event.currentTarget;    
	        if(event.keyCode!=8)
			{
			  if (textarea.value.length> 249){
			        alert("最多为250个字符,字符输入超出限制!");
			        textarea.value=textarea.value.substring(0,249);
			    }
			    return true;
	 	    }
	}
		
	  //选择部门
	function selectdept(id)
	{
		var datas = window.showModalDialog("<%=request.getContextPath() %>/resource/choose/choose_organizationIndex.jsp?temp="+Math.round(Math.random()*10000),'',"dialogWidth=900px;dialogHeight=550px");
		if(typeof(datas) == 'undefined'){
		}else{
			var json1 = eval('(' + datas + ')');
			 document.getElementById("dept_"+id).value = json1.ORG_NAME;
			 document.getElementById(id).value = json1.ORG_ID;
		}
	}
	
	//选择人员
	function selectperson(id)
	{
		 var users = window.showModalDialog("<%=request.getContextPath() %>/resource/choose/chooseAllUser.jsp", window, "dialogWidth:900px;status:no;dialogHeight:500px");
    	if (users != null) {
    		var userIds = [];
            var userNames = [];
            for(var i=0;i<users.length;i++){
                userIds.push(users[i]['userid']);
                userNames.push(users[i]['username']);
            }
			    $("#"+id).val(userNames.join());
		     //   $("#"+id+"_id").val(userIds.join());
		   }
	}
	function changevalue(id){
	 	
	 	var flag = "0";
	 	if(id == 1){
	 		var fileValue = document.getElementById("file1").value;
	 		var a=fileValue.lastIndexOf("\\");
	 		var filename = fileValue.substring(a+1);
			document.getElementById("gongyingshangzizhi").value=filename;
			flag = "1";
		}else if(id == 2){
		    var fileValue = document.getElementById("file2").value;
	 		var a=fileValue.lastIndexOf("\\");
	 		var filename = fileValue.substring(a+1);
			document.getElementById("gongyingshangpingjia").value=filename;
			flag = "2";
		}
		document.getElementById("flag").value=flag;
	}
	//选择外键数据信息
	//参数信息：表明，关联列，显示列
	function selectData(id,tablename,colname,disname,cnname,fieldslist){
	    var fileColname ='hideFileName';
	    if(tablename=='DIC_STANDARD'){
	      fileColname = "YCLJS_GYYW";
	    }
		var datas = window.showModalDialog("<%=basePath%>/codeReviewActionNew!chooseDatalist.action?tablename="+tablename+"&colname="+colname+"&disname="+disname+"&cnname="+escape(encodeURIComponent(cnname))+"&fileColname="+fileColname+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=800px;dialogHeight=500px");
		if(typeof(datas) == 'undefined'){
		}else{
			 var json1 = eval('(' + datas + ')');
	//		 document.getElementById(id).value = json1.ID;
			 var disnamearray = disname.split(',');
			 if(id == "jiancedanwei"){
			    document.getElementById("jiancedanweiId").value = json1.ID;
			 	document.getElementById(id).value = json1[disnamearray[0]];
			 	document.getElementById("jiancedidian").value = json1[disnamearray[2]];
			 }else{
			    document.getElementById(id).value = json1[disnamearray[0]];
			 }
			 
		}
	}
		
   //添加样品
   function addSampleGrid(){
      var toUrl = '<%=request.getContextPath() %>/auto!gotoAdd.action?sign=0&formid=4521&fromtype=flow&byTableValue=&byTableColumn=&flowtaskid='+flowtaskid+'&temp='+Math.round(Math.random()*10000);
	  W.$.dialog({
	        title: '样品添加页面',
	        content: 'url:'+ toUrl,
			okVal: false,//确定按钮文字
	        cancelVal: false,//取消按钮文字
	        min: true, //是否显示最小化按钮
	        max: false,//是否显示最大化按钮
	        fixed: false,//开启静止定位
	        lock: true,//开启锁屏
	        focus: true,//弹出窗口后是否自动获取焦点（4.2.0新增）
	        time: null,//设置对话框显示时间
	        resize: true,//是否允许用户调节尺寸
	        drag: true,//是否允许用户拖动位置
	        cache: false,//是否缓存iframe方式加载的窗口内容页
	        width: 960,
	        height: 500,
	        close: function(){
	        	gridSearchSample(flowtaskid);
		    }
		});
   }
   //刷新样品列表
   function gridSearchSample(flowtaskid){
        jQuery("#gridTableSample").jqGrid('setGridParam',
              {
                  url:'<%=request.getContextPath() %>/autoForms/item!queryZCSampleByTaskId.action?taskId='+flowtaskid
              }).trigger("reloadGrid", [{page:1}]); 
   }
    //修改样品
   function  updateSampleGrid(){
      var ids= $("#gridTableSample").jqGrid("getGridParam", "selarrrow") + "";
		if (!ids) {
		    alert("请先选择记录!");  
		    return false;  
		}
		if(ids.indexOf(",")!=-1){
			  alert("只能选择一条记录!");  
		        return false; 
		}
		var row = jQuery("#gridTableSample").jqGrid('getRowData',ids);//获取选中行.
		var id = row.ID;
		var toUrl = '<%=request.getContextPath() %>/auto!gotoUpdate.action?formid=4521&id='+id+'&flowtaskid='+flowtaskid+'&byTableValue=&byTableColumn=&temp='+Math.round(Math.random()*10000);
		W.$.dialog({
	        title: '样品修改页面',
	        content: 'url:'+ toUrl,
	        okVal: false,//确定按钮文字-->
	        cancelVal: false,//取消按钮文字-->
	        min: true, //是否显示最小化按钮-->
	        max: false,//是否显示最大化按钮-->
	        fixed: false,//开启静止定位-->
	        lock: true,//开启锁屏-->
	        focus: true,//弹出窗口后是否自动获取焦点（4.2.0新增）-->
	        time: null,//设置对话框显示时间-->
	        resize: true,//是否允许用户调节尺寸-->
	        drag: true,//是否允许用户拖动位置-->
	        cache: false,//是否缓存iframe方式加载的窗口内容页
	        width: 960,
	        height: 500,
	        close: function(){
	        	gridSearchSample(flowtaskid);
		    }
		});
   }
   //删除样品
   function deleteSampleGrid(){
		var ids= $("#gridTableSample").jqGrid("getGridParam", "selarrrow") + "";
		if (!ids) {
		    alert("请先选择记录!");  
		    return false;  
		}
		if(!confirm("是否确认删除？")){
			return false;
		}
		var params = {
					"mainIds": ids,
					"tableName":"GWM_SAMPLE"
					};  
		var actionUrl = "<%=request.getContextPath() %>/auto!deleteForm.action";  
		$.ajax({  
			  url : actionUrl,  
		      type : "post", 
		      data : params,  
		      dataType : "json",  
		      cache : false,  
		      error : function(textStatus, errorThrown) {  
		          alert("系统ajax交互错误: " + textStatus.value);  
		      },  
		      success : function(data, textStatus) {
		      	if(data.result=='success'){
		      		alert("删除成功！");       
		      		gridSearchSample(flowtaskid);
		      	}else{
		      		alert("删除失败！");
		      	}
		    }  
		});
	}
	//下载模版
  function downloadSampleModel(){
     window.location.href="<%=request.getContextPath() %>/filemodel/sampleModel.xls";
  }
   //样品模版导入
	  function SampleModeImport(){
	    var result =window.showModalDialog("<%=request.getContextPath() %>/resource/choose/select_excel_auto_form_list.jsp?flag=0&id="+flowtaskid+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=500px;dialogHeight=300px");
		if(result == 'success'){
			gridSearchSample(flowtaskid);
		}
	  }
  
	
	//刷新检测项目列表
   function gridSearchItemGrid(flowtaskid){
        jQuery("#gridTableItem1").jqGrid('setGridParam',
              {
                  url:'<%=request.getContextPath() %>/autoForms/item!queryItemByTaskId.action?type=0&taskId='+flowtaskid
              }).trigger("reloadGrid", [{page:1}]); 
   }
   //刷新其他项目列表
  function gridOtherItemGrid(flowtaskid){
        jQuery("#gridTableItem2").jqGrid('setGridParam',
              {
                  url:'<%=request.getContextPath() %>/autoForms/item!queryItemByTaskId.action?type=1&taskId='+flowtaskid
              }).trigger("reloadGrid", [{page:1}]); 
   }
   //选择检测项目
	function selectItemGrid(){
	    var deptId =$("#jiancedanweiId").val();
	     if(deptId==''){
	         alert("请先选择检测单位!");
	         return false;
	     }
	   var toUrl = '<%=request.getContextPath() %>/workflow/choose_project.jsp?leibie=1&deptId='+deptId+'&taskId='+flowtaskid+'&temp='+Math.round(Math.random()*10000);
		W.$.dialog({
	        title: '选择检测项目',
	        content: 'url:'+ toUrl,
	        okVal: false,//确定按钮文字-->
	        cancelVal: false,//取消按钮文字-->
	        min: true, //是否显示最小化按钮-->
	        max: false,//是否显示最大化按钮-->
	        fixed: false,//开启静止定位-->
	        lock: true,//开启锁屏-->
	        focus: true,//弹出窗口后是否自动获取焦点（4.2.0新增）-->
	        time: null,//设置对话框显示时间-->
	        resize: true,//是否允许用户调节尺寸-->
	        drag: true,//是否允许用户拖动位置-->
	        cache: false,//是否缓存iframe方式加载的窗口内容页
	        width: 1200,
	        height: 600,
	        close: function(){
	        	gridSearchItemGrid(flowtaskid);
		    }
		});
	}
	//删除检测项目及标准
	function deleteItemGrid(){
	    var biaozhunIds = [];
		var s = $("#gridTableItem1").jqGrid('getGridParam', 'selarrrow') + "";
		if (s) {
		   if(!confirm("是否确认删除？")){
				return false;
		   }
		    var actionUrl = "<%=request.getContextPath()%>/autoForms/item!deleteFlowProject.action?taskId="+flowtaskid+"&itemFlowIds="+s+"&temp="+Math.round(Math.random()*10000);  
		    $.ajax({  
		        url : actionUrl,  
		        dataType : "json",  
		        async: false,//取消异步提交
		        error : function(textStatus, errorThrown) {  
		            alert("系统ajax交互错误: " + textStatus);  
		        },  
		        success : function(data, textStatus) {
		        	if(data.result=='success'){
		        	   alert("删除成功!");
		        	  gridSearchItemGrid(flowtaskid);
		        	}else{
		        	  alert("删除失败,请重试!"); 
		        	}
		        }  
		    });  
		}else{
		   alert("请选择数据!");
		   return false;
		}
	}
	//检测项目【保存列表】按钮
	function saveItemGrid(flag){
	   var msg = [];
	   var ids = $("#gridTableItem1").jqGrid('getDataIDs')+"";
	   if(ids){
	      var allIds = ids.split(",");
	      for(var i=0;i<allIds.length;i++){
	           var id = allIds[i];
	           var row = $("#gridTableItem1").jqGrid('getRowData',id);
	           var bzwt = $("#"+id+"_T_BIAOZHUNWEITUO").val();   //标准委托
	           var bgtype = $("#"+id+"_T_BAOGAOTYPE").val();     //报告类型
	           var yaoqiu = $("#"+id+"_T_BGYAOQIU").val();       //报告要求
	           
	            if(bzwt==undefined){
	              bzwt =row.T_BIAOZHUNWEITUO;
	           }
	           
	           if(bgtype==undefined){
	              bgtype =row.T_BAOGAOTYPE;
	           }
	           
	           if(bgtype=='出具原始记录'){
	             yaoqiu = '';
	           }else{
	              if(yaoqiu==undefined){
		              yaoqiu =row.T_BGYAOQIU;
		           }
	           }
	           
	           msg.push(id+"@"+"t_biaozhunweituo ='"+bzwt+"'#t_baogaotype='"+bgtype+"'#t_bgyaoqiu ='"+yaoqiu+"'");
	      }
	 
	    	   var actionUrl = "<%=request.getContextPath()%>/autoForms/item!saveItemGrid.action?flowtaskid="+flowtaskid+"&msg="+escape(encodeURIComponent(msg.join()));  
			    $.ajax({  
			        url : actionUrl,  
			        //data : params,  
			        dataType : "json",  
			        async: false,//取消异步提交
			        error : function(textStatus, errorThrown) {  
			            alert("系统ajax交互错误: " + textStatus);  
			        },  
			        success : function(data, textStatus) {
			           if(data.result=='success'){
			        	  if(flag==0){
			        	     alert("列表保存成功!");
			        	     gridSearchItemGrid(flowtaskid);
			        	  }
			           }else{
			        	  alert("列表保存失败,请重试!"); 
			           }
			        }  
			    }); 
	   }
	}
	//其他检测项目  【添加】按钮
	function addRowtoItem2(){
		    var selectedId = $("#gridTableItem2").jqGrid("getGridParam", "selrow"); 
		    var ids = jQuery("#gridTableItem2").jqGrid('getDataIDs');
		   
		    var rowid = (ids.length ==0 ? 1:parseInt(Math.max.apply(Math,ids))+1); 
		    //获得新添加行的行号
		    var newrowid = rowid;  
		    var dataRow = {  
		     ID: newrowid,
		     T_ITEMNAME:"",
		     T_BIAOZHUNWEITUO:'',
		     T_BAOGAOTYPE:'',
		     T_BGYAOQIU:'',
		     FILE_NAME:''
		    };    
		     //将新添加的行插入到第一列
            $("#gridTableItem2").jqGrid("addRowData", newrowid, dataRow, "first");
            
           
            //设置检测项目可以编辑
            $("#gridTableItem2").jqGrid('setColProp','T_ITEMNAME',{name:'T_ITEMNAME',index:'T_ITEMNAME', width:180,editable: true,edittype:'text'});
            
		    //设置grid单元格可编辑
		    $('#gridTableItem2').jqGrid('editRow', newrowid, false);
	    }
	 //其他检测项目删除行
	 function deleteGridItem3(){
	    var selectedId = $("#gridTableItem2").jqGrid("getGridParam", "selrow"); 
	    if(selectedId){
	       $("#gridTableItem2").jqGrid("delRowData", selectedId); 
	    }
	    else {
	      alert("请选择数据!");
	    }
	 }
	 //存入数据库
	 function saveDataIntoItem(){
	    
	     var itemName =[];
	     var ids = $("#gridTableItem2").jqGrid("getGridParam", "selrow");
	     if(ids){
	           var deptId =$("#jiancedanweiId").val();
			   if(deptId==''){
			         alert("请先选择检测单位!");
			         return false;
			   }
		      var allIds = ids.split(",");
		      for(var i=0;i<allIds.length;i++){
		           var id = allIds[i];
		           var name = $("#"+id+"_T_ITEMNAME").val();
		           if(name!=''&&name!=undefined){
		            itemName.push(name);
		           }
		      }
	   	     var actionUrl = "<%=request.getContextPath()%>/autoForms/item!saveItemIntoGWMItem.action?deptId="+deptId+"&itemName="+escape(encodeURIComponent(itemName.join()));  
		     $.ajax({  
		        url : actionUrl,  
		        dataType : "json",  
		        async: false,//取消异步提交
		        error : function(textStatus, errorThrown) {  
		            alert("系统ajax交互错误: " + textStatus);  
		        },  
		        success : function(data, textStatus) {
		           if(data.result=='success'){
		        	   alert("存入数据库成功!");
		           }else{
		        	  alert("存入数据库失败,请重试!"); 
		           }
		        }  
		    }); 
	    }
	    else{
	      alert("请先选择数据!");
	    }
	  }
	  //其他检测项目保存列表
	  function saveGridOtherItem(flag){
	       var shifouweikong = true;
	       var msg = [];
		   var ids = $("#gridTableItem2").jqGrid('getDataIDs')+"";
		   if(ids){
		      var allIds = ids.split(",");
		      for(var i=0;i<allIds.length;i++){
		           var id = allIds[i];
		           var row = $("#gridTableItem2").jqGrid('getRowData',id);
		           var itemName =$.trim($("#"+id+"_T_ITEMNAME").val());
		           var bzwt = $("#"+id+"_T_BIAOZHUNWEITUO").val();   //标准委托
		           var bgtype = $("#"+id+"_T_BAOGAOTYPE").val();     //报告类型
		           var yaoqiu = $("#"+id+"_T_BGYAOQIU").val();       //报告要求
		           
		           if(itemName==undefined||itemName==''){
		                itemName = row.T_ITEMNAME;
		           }
		      
		           if(itemName==''||itemName.indexOf('INPUT')>0){
		             shifouweikong = false;
		             break;
		           }
		           if(bzwt==undefined){
			           bzwt = row.T_BIAOZHUNWEITUO;
		           }
		           
		           if(bgtype==undefined){
		               bgtype =  row.T_BAOGAOTYPE;
		           }
		           
		           if(bgtype=='出具原始记录'){
		             yaoqiu = '';
		           }else{ 
		             if(yaoqiu==undefined){
			             yaoqiu = row.T_BGYAOQIU;
		             }
		           }
		         
		            msg.push("'"+itemName+"'#'"+itemName+"'#'"+bzwt+"'#'"+bgtype+"'#'"+yaoqiu+"'");  //手动添加项目  检测参数的值=检测项目
		       }
		           if(!shifouweikong){
		                alert("检测项目不能为空");
		                shifouweikong = false;
		           }else{
		                var actionUrl = "<%=request.getContextPath()%>/autoForms/item!saveGridOtherItem.action?msg="+escape(encodeURIComponent(msg.join()))+"&flowtaskid="+flowtaskid;  
					    $.ajax({  
					        url : actionUrl,  
					        //data : params,  
					        dataType : "json",  
					        async: false,//取消异步提交
					        error : function(textStatus, errorThrown) {  
					            alert("系统ajax交互错误: " + textStatus);  
					        },  
					        success : function(data, textStatus) {
					           if(data.result=='success'){
					        	   if(flag==0){
					        	     alert("列表保存成功!");
					        	     gridOtherItemGrid(flowtaskid);
					        	   }
					           }else{
					        	  alert("列表保存失败,请重试!"); 
					        	  return false;
					           }
					        }  
					    });
		           }
		    	    
		   } else{
		      if(flag==0){
		         alert("请先添加数据!");
		      }
		   }
		   return shifouweikong;
	  }

   
   function buttonDisabled(){				
		for (i = 0;i < document.all.length; i++)
		{
			if (document.all[i].type == 'button' || document.all[i].type == 'submit' || document.all[i].type == 'reset')
			{
				document.all[i].disabled = true;
			}
		}			
	}
	function changeButtonDisabled(){	
		for (i = 0;i < document.all.length; i++)
		{
			if (document.all[i].type == 'button' || document.all[i].type == 'submit' || document.all[i].type == 'reset'){
				document.all[i].disabled = false;
			}
		}	
    }
    //上传附件    flag : 0为项目列表上传附件 1为原始记录上传附件
	  function itemGrid1UploadFile(gridName,flag){
	      var ids = $("#"+gridName).jqGrid("getGridParam", "selarrrow")+"";
	      if(!ids){
	         alert("请选择数据!");
	         return false;
	      }
	      if(flag=='0'){
		      if(gridName=='gridTableItem2'){
		        var allids = ids.split(",");
		        for(var i=0;i<allids.length;i++){
		            var row = jQuery("#"+gridName).jqGrid('getRowData',allids[i]);//获取选中行
		            if(row.ID!=row.ITEMFLOWID){
		               alert("请先保存列表!");
		               return false;
		            }
		        }
		      }
	      }
	    
	     var datas = window.showModalDialog("<%=request.getContextPath()%>/workflow/changguijiance_uploadFile.jsp?itemflowid="+ids+"&flag="+flag+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=400px;dialogHeight=300px");
	     if(gridName=='gridTableItem1'){
	         gridSearchItemGrid(flowtaskid);
	     }
	    else if(gridName=='gridTableItem2'){
	         gridOtherItemGrid(flowtaskid);
	     }
	  }
    //下载附件
	  function downloafAnnex(flag,annexId){
	     window.location.href="<%=request.getContextPath()%>/codeReviewActionNew!downloafAnnex.action?flag="+flag+"&id="+annexId;
	  }

   </script>
 	<style type="text/css">
 		body{
 			background:#ffffff; background-image:url(images/);
 		}
   		html{
		    overflow-x: hidden;
			overflow-y: hidden;
		}  	
		.formTableNew textarea{border: 1px solid #999;padding: 5px;width: 760px;-moz-border-radius: 3px;border-radius: 3px;margin-bottom: 5px;color: #666;background: url(../images/input_bg.gif) repeat-x top;}
   </style>
  </head>
  
  <body style="overflow-y: scroll;" onunload="guanbi()">
<form id="pageFrom" action="" enctype="multipart/form-data" method="post">
        <input type="hidden" name="flowid" id="flowid" value="${flowid}">
     	<input type="hidden" name="stateid" id="stateid" value="${stateid}">
     	${steptcontent}
     	<input type="hidden" id="bianzhirenyuan" name="bianzhirenyuan" value="" />
     	<input type="hidden" id="pizhunrenyuan" name="pizhunrenyuan" value="" />
     	<input type="hidden" id="jieshoufangdaibiao" name="jieshoufangdaibiao" value="" />
     	<input type="hidden" id="mainid" name="mainid" value="" />
     	<input type="hidden" id="flowtaskid" name="flowtaskid" value="${flowtaskId}" />
     	<input type="hidden" id="taskinfoid" name="taskinfoid" value="" />
     	<input type="hidden" id="weituodanid" name="weituodanid" value="${requestScope.id }" />
  		<table width="100%" border="0" align="center" cellpadding="5" cellspacing="5" class="formTableNew">
  		    <tr>
  		    	<td align="right">流程名称：</td>
  		    	<td colspan="3" align="left">
	  			    <input  type="text"  id="flowname" maxlength="50" name="flowname" style="border: 1px solid #999;padding: 5px;width: 738px;"  value="整车可靠性试验流程" />
  			    </td>
  		    </tr>
  			<tr>
  			  <td align="right">任务名称：</td>
  			  <td align="left">
  			    <input  type="text"  id="renwuname" maxlength="50" name="renwuname" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">检测单位：</td>
  			   <td align="left">
  			    <input type="hidden" id="jiancedanweiId" name="jiancedanweiId" />
  			    <input  type="text"  id="jiancedanwei" readonly name="jiancedanwei" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  			   	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			   	<img src="web/images/form_icon_1.gif" style="cursor:hand; vertical-align: middle;" onclick="selectData('jiancedanwei','GWM_JIANCEDANWEI','ID','T_JIANCEDANWEI,T_GONGSIDAIMA,T_JIANCEDIDIAN,T_GONGSIDIZHI','检测单位','null','3881')" />
  			   </td>
  			</tr>
  			<tr>
  			  <td align="right">检测地点：</td>
  			  <td align="left">
  			    <input  type="text"  id="jiancedidian" readonly name="jiancedidian" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">申请单位：</td>
  			   <td align="left">
  			    <input  type="text"  id="shenqingdanwei" maxlength="50" name="shenqingdanwei" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			   </td>
  			</tr>
  			<tr>
  			  <td align="right">联系人：</td>
  			  <td align="left">
  			  	 <input  type="text"  id="lianxiren" readonly name="lianxiren" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="<%=request.getSession().getAttribute("username").toString() %>" />
  			     <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">申请日期：</td>
  			  <td align="left">
  			    <input  type="text"  id="shenqingdate" readonly maxlength="50"  name="shenqingdate" onClick="WdatePicker()" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="<%=DateUtilsAll.dateToStringShort(new Date()) %>" />
  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
  			<tr>
  			  <td align="right">联系电话：</td>
  			  <td align="left">
  			    <input  type="text"  id="lianxidianhua" maxlength="50"  name="lianxidianhua" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  			  </td>
  			  <td align="right">地址：</td>
  			  <td align="left">
  			     <input  type="text"  id="dizhi" maxlength="50" name="dizhi" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  			     <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
  			<tr>
  			  <td align="right">邮编：</td>
  			  <td align="left">
  			    <input  type="text"  id="youbian" maxlength="50"  name="youbian" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  			  </td>
  			  <td align="right">检测目的：</td>
  			  <td align="left">
  			     <input  type="text"  id="jiancemudi" maxlength="50" name="jiancemudi" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="" />
  			     <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
 			<tr>
		    <td align="right"  >项目特殊说明：</td>
		    <td >
		    	<div class="div">
					<textarea rows="5" cols="100" id="xiangmuteshushuoming" name="xiangmuteshushuoming" onkeydown="countlen1(this);" style="width: 250px;"></textarea>
				</div>	
		    </td>
		    <td align="right"  >样品特殊说明：</td>
		    <td >
		    	<div class="div">
					<textarea rows="5" cols="100" id="yangpinteshushuoming" name="yangpinteshushuoming" onkeydown="countlen1(this);" style="width: 250px;"></textarea>
				</div>	
		    </td>
		  </tr>
		  <tr>
		  	  <td align="right">项目附件：</td>
  			  <td align="left">
  			    <jsp:include page="../fileupload/attachment.jsp?id=${requestScope.id }&column=xiangmu&show=n" ></jsp:include>
  			  </td>
  			  <td align="right">样品附件：</td>
  			  <td align="left">
  			    <jsp:include page="../fileupload/attachment.jsp?id=${requestScope.id }&column=yangpin&show=n" ></jsp:include>
  			  </td>
		  </tr>
		  <tr>
		    <td colspan='4' align='center'>
		      <div id='tt1' class='easyui-tabs' style='width:750px;height：600px'>
		        <div title='样       品' style='padding:10px'>
		          <input id='saveBtn1' type='button'  value='添 加' onclick="addSampleGrid()" class='form_bt_orange'/>
				  <input id='updateBtn1' type='button'  value='修 改'  onclick="updateSampleGrid()" class='form_bt_orange'/>
				  <input id='deleteBtn1' type='button'  value='删 除' onclick="deleteSampleGrid()" class='form_bt_orange'/>
				  <input id='deleteBtn1' type='button'  value='下载模版' onclick="downloadSampleModel()" class='form_bt_orange'/>
				  <input id='deleteBtn1' type='button'  value='模版导入' onclick="SampleModeImport()" class='form_bt_orange'/>

                  <table id="gridTableSample"></table>
                 <div id="gridPagerSample"></div></div>
                 <div title='检测项目' style='padding:10px'>
                    <input id='selectBtn2' type='button'  value='选择项目' onclick="selectItemGrid()" class='form_bt_orange'/> &nbsp;
					<input id='deleteBtn2' type='button'  value='删 除' onclick="deleteItemGrid()" class='form_bt_orange'/> &nbsp;
					<input id='saveBtn2' type='button'  value='保存列表' onclick="saveItemGrid(0)" class='form_bt_orange'/> &nbsp;
					<!--input id='saveBtn2' type='button'  value='上传附件' onclick="itemGrid1UploadFile('gridTableItem1','0')" class='form_bt_orange'/--> &nbsp;
                  <table id="gridTableItem1"></table>
                  <div id="gridPagerItem1"></div>
				 </div>
				 <!--div title='其他检测项目' style='padding:10px'>
				    <input id='addBtn3' type='button'  value='添 加' onclick="addRowtoItem2()" class='form_bt_orange'/>&nbsp;
					<input id='deleteBtn3' type='button'  value='删 除' onclick="deleteGridItem3()" class='form_bt_orange'/> &nbsp;
					<input id='saveBtn3' type='button'  value='保存列表'  onclick="saveGridOtherItem(0)" class='form_bt_orange'/> &nbsp;
					<input id='saveBtn3' type='button'  value='存入数据库' onclick="saveDataIntoItem()" class='form_bt_orange'/> &nbsp;
				   <table id="gridTableItem2"></table>
				   <div id="gridPagerItem2"></div>
				 </div-->
			</td>
		</tr>
		</table>
		<table width="100%" border="0" align="center" class="formTableNew">
		  <tr>
			<td align="center">
				<input id="saveBtn" type="button" value="保 存" class="form_bt_orange" />
		    	<input id="submitBtn" type="button" value="提 交" class="form_bt_orange" />
		    	<input type="button" id="closeBtn" value="取 消" class="form_bt_grey" />
		    </td>
		  </tr>
		  <tr>
		  	<td>&nbsp;&nbsp; </td>
		  </tr>
		</table>
	<!--表单结束-->
	</form>
  </body>
</html>
